package prepro;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Stack;

import myLucene.GetTime;
import myLucene.Props;
import myLucene.TfIdfOld;

public class SerializeTermsToInt {

	/**
	 * @param args
	 * @throws Exception 
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException, Exception {
		// TODO Auto-generated method stub
//		System.out
//		.println("Start IntToTerms: " + GetTime.getTime());
//		long start = System.currentTimeMillis();
//		BufferedReader br = new BufferedReader(
//				new FileReader(new File(
//				"/local/joofeit/termsToIntPunt")));
//		String[] termsToInt = new String[Props.dictSize];
//		String line = "";
//		while ((line = br.readLine()) != null) {
//			if (line.split(" ").length != 2) {
//				throw new Exception(TfIdfOld.class.getName()
//						+ " "
//						+ Thread.currentThread().getStackTrace()[1]
//								.getMethodName());
//			} else {
//				termsToInt[(Integer.parseInt(line.split(" ")[0]))] = line
//						.split(" ")[1];
//			}
//
//		}
//		System.out.println(TfIdfOld.class.getName() + " Time need for termsToInt "
//				+ GetTime.getDuration(start, System.currentTimeMillis()));
//		br.close();
//		serializeArray(termsToInt);
		String[] arrayObj= deserializeArray();
//		printTermsToInt(arrayObj);
	}

	public static void serializeArray(String[] termsToInt)
			throws FileNotFoundException, IOException{
		System.out.println("Start serialize TermsToInt");
		ObjectOutputStream o_out = new ObjectOutputStream(new FileOutputStream(
				new File("/local/joofeit/termToInt.data")));
		o_out.writeObject(termsToInt);
		o_out.close();
	}

	public static String[] deserializeArray() throws FileNotFoundException,
			IOException, ClassNotFoundException{
		System.out.println("Start deserializeArray: termToInt.data");
		long start = System.currentTimeMillis();
		File file = new File("/local/joofeit/termToInt.data");
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
		String[] array = (String[]) in.readObject();
		System.out.println(GetTime.getDuration(start, System
				.currentTimeMillis()));
		return array;
	}
	public static void printTermsToInt(String[] array){
		for(String s: array)
			System.out.println(s);
	}

}
